package com.rykj.energy.database.service.impl;

import com.rykj.energy.common.dto.TaskCameraRelationDto;
import com.rykj.energy.common.enums.TaskState;
import com.rykj.energy.database.mapper.CameraMapper;
import com.rykj.energy.database.mapper.TaskCameraRelationMapper;
import com.rykj.energy.database.pojo.TaskCameraRelation;
import com.rykj.energy.database.service.ITaskCameraRelationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service("taskCameraRelationService")
@Slf4j
public class TaskCameraRelationServiceImpl implements ITaskCameraRelationService {

    @Autowired
    private TaskCameraRelationMapper taskCameraRelationMapper;
    @Autowired
    private CameraMapper cameraMapper;

    @Override
    public void save(TaskCameraRelationDto relation) throws Exception {

        TaskCameraRelation tr = new TaskCameraRelation();
        BeanUtils.copyProperties(relation,tr);
        tr.setStatus(TaskState.run.getCode());
        tr.setCreateTime(new Date());
        tr.setUpdateTime(new Date());
        tr.setOrgId(cameraMapper.selectById(tr.getCameraId()).getOrgId());

        taskCameraRelationMapper.insert(tr);
    }

    @Override
    public void updateTaskCamera(TaskCameraRelationDto relation) throws Exception {

        relation.setUpdateTime(new Date());
        taskCameraRelationMapper.updateTaskCamera(relation);
    }
}
